﻿using CJAtech.BBS.Business;
using CJAtech.BBS.DataEntity;
using Qiniu.FileOp;
using Qiniu.IO;
using Qiniu.IO.Resumable;
using Qiniu.RPC;
using Qiniu.RS;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TjZheng.Framework;
using TjZheng.Qiniu;
using CJAtech.BBS.Process;

namespace TjZheng.Example.MVC.Controllers
{
    public class QiNuController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult UploadImage(HttpPostedFileWrapper objImageFile)
        {
            return Content(objImageFile.FileName);
            PutPolicy policy = new PutPolicy("cjatech", 3600);
            string upToken = policy.Token();
            PutExtra extra = new PutExtra();
            IOClient client = new IOClient();
            PutRet objPutRet = client.Put(upToken, objImageFile.FileName, objImageFile.InputStream, extra);
            return Content(objPutRet.Response);
        }

        public ActionResult GetImage()
        {
            string baseUrl = GetPolicy.MakeBaseUrl("7vzrt1.com2.z0.glb.qiniucdn.com", "无标题.png");
            string private_url = GetPolicy.MakeRequest(baseUrl);
            return Redirect(private_url);
        }

        public ActionResult CreateImageThumbnail()
        {
            //ImageMogrify imageMogr = new ImageMogrify
            //{
            //    Thumbnail = "!150x150r",
            //    Gravity = "center",
            //    //Rotate = 90,
            //    //Crop = "!50x50",
            //    Quality = 50,
            //    AutoOrient = true
            //};
            //string mogrUrl = imageMogr.MakeRequest("http://7vzrt1.com2.z0.glb.qiniucdn.com/无标题.png");
            //mogrUrl = GetPolicy.MakeRequest(mogrUrl);
            //return Redirect(mogrUrl);
            //http://7vzrt1.com2.z0.glb.qiniucdn.com/Koala.jpg?e=1432696354&token=15-Roqdhzc8GYeG40ryapSNwgfogx2_oMMZ7s1S_:3woGoezWoXuAbO0re3-pcfEnly0=

            //string imageUrl = "http://7vzrt1.com2.z0.glb.qiniucdn.com/Koala.jpg";
            //return Redirect(imageUrl.CreateThumbnailFromQiniu(50, 50, 80));

            string imageUrl = "http://7vzrt1.com2.z0.glb.qiniucdn.com/Koala.jpg";
            return Redirect(imageUrl.CreateThumbnailFromQiniu(50, 80));
        }

        public ActionResult CreateContentImage()
        {
            ArticleInfoProcess objArticleInfoProcess = new ArticleInfoProcess("CJAtech.Benz.ConnectionString", "");
            return View(objArticleInfoProcess.GetArticleResultInfo(166, true));
        }

    }
}
